package rad.framework.security.jpa;

import javax.persistence.PrePersist;
import javax.persistence.PreRemove;
import javax.persistence.PreUpdate;

/**
 * This callback listener checks entity permissions.
 * 
 * @author boudyacho
 * 
 */
public class MutatePermissionCallbackListener {

	/**
	 * @param entity
	 */
	@PrePersist
	public void doPrePersist(Object entity) {
		PermissionsUtil.doCheck(entity, Action.INSERT);
	}

	/**
	 * @param entity
	 */
	@PreUpdate
	public void doPreUpdate(Object entity) {
		PermissionsUtil.doCheck(entity, Action.UPDATE);
	}

	/**
	 * @param entity
	 */
	@PreRemove
	public void doPreRemove(Object entity) {
		PermissionsUtil.doCheck(entity, Action.DELETE);
	}
}
